#ifndef __TOCUTIL_H__
#define __TOCUTIL_H__

#include <math.h>
#include <stdlib.h>
#include <time.h>
#include "boids.h"

enum Quad{
	FIRST = 1,
	SECOND,
	THIRD,
	FOURTH
};

typedef struct {
	GLfloat x;
	GLfloat y;
}TocPoint_t;

TocPoint_t getCentroid(int N, boid_t boidSet[]);

static inline GLfloat genNum(void)
{
	/* srandom(time(NULL)); */
	return ((random() % 1000) * 0.001);
}

static inline GLfloat getDistance(boid_t p1, boid_t p2)
{
	const GLfloat deltaX = p2.x - p1.x;
	const GLfloat deltaY = p2.y - p1.y;

	/* printf("%f, %f\n", deltaX, deltaY); */

	return (GLfloat)sqrt((deltaX * deltaX) + (deltaY * deltaY));
}

static inline void setQuadrant(boid_t *me)
{
	const GLfloat x = me->x;
	const GLfloat y = me->y;

	if(x >= 0 && y >= 0)
		me->quadrant = FIRST;
	else if (x < 0 && y >= 0)
		me->quadrant = SECOND;
	else if (x < 0 && y < 0)
		me->quadrant = THIRD;
	else if (x >= 0 && y < 0)
		me->quadrant = FOURTH;
}

static inline GLuint getRandomGhoulID(void)
{
	srandom(time(NULL));
	return (random() % BOID_N_BODIES);
}

#endif  /* __TOCUTIL_H__ */
